
$(function(){
	/*chrome.extension.sendMessage({'txt':'content'},function(d){
		alert('this is content.');
		console.log(d);
	});*/
	function pageInfo(){
		var page = $('<div>');
		page.html('<div>页面pv:123123123</div><div>页面uv:123123123</div><div><table><tr><td>点位</td><td>点击数</td><td>占比</td></tr><tr><td>1.DS3.aN3.1</td><td>13231</td><td>10%</td></tr></table></div>');
		page.addClass('page');
		$(document.body).append(page);

	};
	function getSon(obj,index){
		var font = $('<span>');
		var tt = $(obj);
		tt.on('click',function(){
			event.preventdefault();
		});
		


		pos=tt.css('position');
		if(pos == 'absolute'){

		}else{
			tt.attr('style','position:relative;');
		};
		tt.append(font);
		font.html('1231231');
		font.addClass('toast');
		font.addClass('zoom');
		font.on('click',function(e){
			event.preventDefault();
			alert('font click');
		});
		tt.on("mouseover mouseout",function(event){
			 if(event.type == "mouseover"){
			  	font.css({'opacity':1});
			  	font.removeClass('zoom');
			 }else if(event.type == "mouseout"){
			 	font.css({'opacity':0.4});
			 	font.addClass('zoom');
			 };
		});
	};

	var port = chrome.runtime.connect({name: "contentPort"}); 
		port.onMessage.addListener(function(cmd) {
			//if(lock) return;
				

				if(cmd.command == 'on' || (cmd.command == 'content' && cmd.st == 'true')){
					pageInfo();
					var ilog = $('[data-ilog]');
					ilog.each(function(index,ele){
						var tt = $(ele);
						var data = $(ele).attr('data-ilog');
						if(data.indexOf('|') != -1){
							str = data.split('|')[1];
							var son = tt.find(str);
							son.each(function(index,ele){
								getSon(ele,index);
							});
						}else{
							getSon(tt);
						};		
					});
					
					port.postMessage({cmd: "xhrend"}); 

				}else if(cmd.command == 'off'){//
					window.location.reload();
				};
		});



});
chrome.extension.onMessage.addListener(function(objRequest,_,sendResponse){
    if(objRequest.txt == 'content'){
        contentResponse = sendResponse;
    }else{
        popupResponse = sendResponse;
    };

    console.log(objRequest);
    console.log(_);
    console.log(sendResponse);
    sendResponse({'status':'pppppppppp'});
});